﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using CustomsSystem.Model;
using Maticsoft.DBUtility;

namespace CustomsSystem.DAL
{
    public class ChangeService
    {
        /// <summary>
        /// 更改客户密码
        /// </summary>
        public bool ClientChange(CustomsSystem.Model.password_change model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Cu_Client set ");
            if (model.NewPassWord1 != null)
            {
                strSql.Append("PassWord='" + model.NewPassWord1 + "' ");
            }
            else
            {
                strSql.Append("PassWord= null ");
            }
            strSql.Append("where ClientName='" + model.ClientName + "' and PassWord='" + model.OldPassWord + "'");
            int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 密码确认
        /// </summary>
        public bool Judge(CustomsSystem.Model.password_change model)
        {
            if (model.NewPassWord1 == model.NewPassWord2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更改用户密码
        /// </summary>
        public bool UserChange(CustomsSystem.Model.password_change model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Cu_User set ");
            if (model.NewPassWord1 != null)
            {
                strSql.Append("PassWord='" + model.NewPassWord1 + "' ");
            }
            else
            {
                strSql.Append("PassWord= null ");
            }
            strSql.Append("where UserName='" + model.UserName + "' and PassWord='" + model.OldPassWord + "'");
            int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rowsAffected > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
